<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<!--author: AGolubinskyy -->
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:f="http://java.sun.com/jsf/core" 
      xmlns:p="http://primefaces.prime.com.tr/ui" 
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>Request lister</title>
    </h:head>
    <h:body>
        <ui:component>
            <h:form>
                <h:outputText value="Show:"/>
                <h:panelGroup rendered="#{rlb.userRole == 'manager' || rlb.userRole == 'president'}">
                    <h:outputText value=" User:"/>
                    <f:ajax execute="@this" render="requestList">
                        <h:selectOneMenu value="#{rlb.userToShow}">
                            <f:selectItems value="#{rlb.users}"/>
                        </h:selectOneMenu> 
                    </f:ajax>
                </h:panelGroup>
                <h:panelGroup  rendered="#{rlb.userRole == 'president'}">
                    <f:ajax execute="@this" render="requestList">
                        <h:outputText value=" Manager:"/>
                        <h:selectOneMenu value="#{rlb.managerToShow}">
                            <f:selectItems value="#{rlb.managers}"/>
                        </h:selectOneMenu> 
                    </f:ajax>
                </h:panelGroup>
                <h:panelGroup>
                    <h:outputText value=" Category:"/>
                    <f:ajax execute="@this" render="productList requestList">
                        <h:selectOneMenu value="#{rlb.categoryToShow}">
                            <f:selectItems value ="#{rlb.categories}"/>
                        </h:selectOneMenu>
                    </f:ajax>
                </h:panelGroup>
                <h:panelGroup>
                    <h:outputText value=" Product:"/>
                    <f:ajax execute="@this" render="requestList">
                        <h:selectOneMenu value="#{rlb.productToShow}" id="productList">
                            <f:selectItems value="#{rlb.products}"/>
                        </h:selectOneMenu> 
                    </f:ajax>
                </h:panelGroup>
                <h:panelGroup>
                    <h:outputText value=" State"/>
                    <f:ajax execute="@this" render="requestList">
                        <h:selectOneMenu value="#{rlb.statusToShow}">
                            <f:selectItems value="#{rlb.statuses}"/>
                        </h:selectOneMenu>
                    </f:ajax>
                </h:panelGroup>
                <br/>


                <p:dataTable value="#{rlb.requests}" var="r" 
                                 paginator="true" rows="30" id="requestList" 
                                 dynamic="false" scrollable="false" 
                                 style="width:100%;">
                    
                    <p:column>
                        <f:facet name ="header">
                            <h:outputText value="ID"/>
                        </f:facet>
                        #{r.id}
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Product"/>
                        </f:facet>
                        #{r.product.description}
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Category"/>
                        </f:facet>
                        #{r.product.prodCategory.description}
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Desctiption"/>
                        </f:facet>
                        #{r.description}
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Creation date"/>
                        </f:facet>
                        <h:outputText value="#{r.inDate}">
                            <f:convertDateTime pattern="dd.MM.yy hh:mm"/>
                        </h:outputText>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Status"/>
                        </f:facet>
                        <h:outputText value ="#{r.status.description}" rendered="#{r.status.description == 'In progress'}" styleClass="inProgressStatus"/>
                        <h:outputText value ="#{r.status.description}" rendered="#{r.status.description == 'Completed'}" styleClass="completedStatus"/>
                        <h:outputText value ="#{r.status.description}" rendered="#{r.status.description == 'Rejected'}" styleClass="rejectedStatus"/>
                    </p:column>
                    <p:column rendered="#{rlb.userRole == 'manager' || rlb.userRole == 'president'}">
                        <f:facet name="header">
                            <h:outputText value="From user"/>
                        </f:facet>
                        #{r.user.firstName} #{r.user.lastName}
                    </p:column>
                    <p:column rendered="#{rlb.userRole == 'manager'}">
                        <f:facet name="header">
                            <h:outputText value="Actions"/>
                        </f:facet>
                        <h:panelGroup rendered="#{r.status.description == 'In progress'}">
                            <h:commandLink action="#{rlb.complete(r)}">
                                <f:ajax execute="@this comment" render="@form"/>
                                <h:outputText value="Complete" styleClass="completedStatus"/>
                            </h:commandLink>
                            <h:outputText value="  "/>
                            <h:commandLink action="#{rlb.reject(r)}">
                                <h:outputText value="Reject" styleClass="rejectedStatus"/>
                                <f:ajax execute="@this comment" render="@form"/>
                            </h:commandLink>
                        </h:panelGroup>
                    </p:column>
                     
                    <p:column> 
                    <f:facet name="header">
                            <h:outputText value="Comment"/>
                     </f:facet>
                        <h:outputText value="#{r.comment}" rendered="#{r.status.description == 'Rejected'}"/>
                        <p:inputText value="#{rlb.comment}" rendered="#{r.status.description == 'In progress' and rlb.userRole == 'manager'}" id="comment"/>
                    </p:column>
                        
                </p:dataTable>
                <h:commandLink value="Get PDF" target="_blank" action="#{rlb.exportPdfFile()}" rendered="#{rlb.userRole != 'user'}"/>
                <p:messages globalOnly="true"/>
            </h:form>
        </ui:component>
    </h:body>
</html>
